#include<graphics.h>
#include<conio.h>
#include<math.h>

#define high 480
#define width 640
#define pi 3.14159


int main()
{
	initgraph(width,high);
	int center_x,center_y;
	center_x=width/2;
	center_y=high/2;
	int secondlength=width/5;
	int minutelength=width/6;
	int hourlength=width/7;
	int secondend_x,secondend_y;
	int minuteend_x,minuteend_y;
	int hourend_x,hourend_y;
	float secondangle;
	float minuteangle;
	float hourangle;



	SYSTEMTIME ti;


	BeginBatchDraw();
	while(1)
	{
		//绘制表盘
		setlinestyle(PS_SOLID,1);
		setcolor(WHITE);
		circle(center_x,center_y,width/4);


		//画刻度
		int x,y,i;
		for(i=0;i<60;i++)
		{
			x=center_x+int(width/4.3*sin(pi*2*i/60));
			y=center_y+int(width/4.3*cos(pi*2*i/60));


			if(i%15==0)
				bar(x-5,y-5,x+5,y+5);
			else if(i%5==0)
				circle(x,y,3);
			else
				putpixel(x,y,WHITE);
		}


		outtextxy(center_x-25,center_y+width/6,"我的时钟");


		GetLocalTime(&ti);//获取当前时间
		//秒钟角度变化
		secondangle=ti.wSecond*2*pi/60;
		//分钟角度变化
		minuteangle=ti.wMinute*2*pi/60+secondangle/60;
		//时钟角度变化
		hourangle=ti.wHour*2*pi/12+minuteangle/12;


		//由角度决定的秒钟短点坐标
		secondend_x=center_x+secondlength*sin(secondangle);
		secondend_y=center_y-secondlength*cos(secondangle);


		//由角度决定的分钟短点坐标
		minuteend_x=center_x+minutelength*sin(minuteangle);
		minuteend_y=center_y-minutelength*cos(minuteangle);


		//由角度决定的时钟短点坐标
		hourend_x=center_x+hourlength*sin(hourangle);
		hourend_y=center_y-hourlength*cos(hourangle);

		
		
		setlinestyle(PS_SOLID,2);
		setcolor(RED);
		line(center_x,center_y,secondend_x,secondend_y);
		setlinestyle(PS_SOLID,5);
		setcolor(BLUE);
		line(center_x,center_y,minuteend_x,minuteend_y);
		setlinestyle(PS_SOLID,10);
		setcolor(YELLOW);
		line(center_x,center_y,hourend_x,hourend_y);
		FlushBatchDraw();


		Sleep(50);
		
		setcolor(BLACK);
		setlinestyle(PS_SOLID,2);
		line(center_x,center_y,secondend_x,secondend_y);
		setlinestyle(PS_SOLID,5);
		line(center_x,center_y,minuteend_x,minuteend_y);
		setlinestyle(PS_SOLID,10);
		line(center_x,center_y,hourend_x,hourend_y);
	}
	EndBatchDraw();
	getch();
	closegraph();


	return 0;
}